home *** CD-ROM | disk | FTP | other *** search
/ Aminet 38 / Aminet 38 (2000)(Schatztruhe)[!][Aug 2000].iso / Aminet / util / moni / Scout-src.lha / src / objects / scout_commands.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-03-09  |  6.6 KB  |  229 lines

  1. /**
  2.  * Scout - The Amiga System Monitor
  3.  *
  4.  *------------------------------------------------------------------
  5.  *
  6.  * This program is free software; you can redistribute it and/or modify
  7.  * it under the terms of the GNU General Public License as published by
  8.  * the Free Software Foundation; either version 2 of the License, or
  9.  * any later version.
  10.  *
  11.  * This program is distributed in the hope that it will be useful,
  12.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.  * GNU General Public License for more details.
  15.  *
  16.  * You should have received a copy of the GNU General Public License
  17.  * along with this program; if not, write to the Free Software
  18.  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  19.  *
  20.  * You must not use this source code to gain profit of any kind!
  21.  *
  22.  *------------------------------------------------------------------
  23.  *
  24.  * @author Andreas Gelhausen
  25.  * @author Richard Körber <rkoerber@gmx.de>
  26.  */
  27.  
  28.  
  29.  
  30. #include "scout_commands.h"
  31.  
  32. extern struct ExecBase  *SysBase;
  33.  
  34. int  comcnt;
  35.  
  36. struct Remember *ComRememberKey;
  37.  
  38. char * GetUCType (LONG uc) {
  39.    char *UCTypeText[] = {
  40.       "SYSTEM","INTERNAL","DISABLED"
  41.    };
  42.  
  43.    LONG UCType[] = {
  44.       CMD_SYSTEM,CMD_INTERNAL,CMD_DISABLED,NULL
  45.    };
  46.  
  47.    int i = 0;
  48.  
  49.    while (UCType[i]) {
  50.       if (uc == UCType[i]) {
  51.          return (UCTypeText[i]);
  52.       }
  53.       i++;
  54.    }
  55.    return (NULL);
  56. }
  57.  
  58. __asm LONG comlist_dspfunc(register __a2 char **array, register __a1 struct CommandEntry *comentry, register __a0 struct Hook *hook) {
  59.    if (comentry) {
  60.       *array++ = comentry->cm_address;
  61.       *array++ = comentry->cm_name;
  62.       *array++ = comentry->cm_uc;
  63.       *array++ = comentry->cm_lower;
  64.       *array++ = comentry->cm_upper;
  65.       *array++ = comentry->cm_size;
  66.       *array   = NULL;
  67.    } else {
  68.       *array++ = ESC "bAddress";
  69.       *array++ = ESC "bName";
  70.       *array++ = ESC "bUseCount";
  71.       *array++ = ESC "b" ESC "cLower";
  72.       *array++ = ESC "b" ESC "cUpper";
  73.       *array++ = ESC "bSize";
  74.       *array++ = NULL;
  75.    }
  76.    return(0);
  77. }
  78.  
  79. struct Hook comlist_dsphook = {
  80.  {NULL, NULL},
  81.  (ULONG (* )())comlist_dspfunc,
  82.  NULL, NULL
  83. };
  84.  
  85. void FreeCommands (void) {
  86.    MyFreeStructs (&ComRememberKey, NULL, comlist);
  87. }
  88.  
  89. int GetCommands (struct CommandEntry **first) {
  90.    struct   Segment        *segment;
  91.    struct   CommandEntry   *comentry,*previous = NULL;
  92.    long     *seg, size;
  93.    char     *tmp;
  94.  
  95.    int comcnt = 0;
  96.    *first = 0;
  97.  
  98.    if (clientstate) {
  99.       if (SendDaemon ("GetComList")) {
  100.          while ((comentry = AllocRemember (&ComRememberKey, sizeof (struct CommandEntry), MEMF_ANY|MEMF_CLEAR)) \
  101.            && (ReceiveDecodedEntry ((UBYTE *) comentry, sizeof (struct CommandEntry)))) {
  102.             IsHex (comentry->cm_address, (long *) &comentry->cm_adr);
  103.  
  104.             if (! *first)
  105.                *first = comentry;
  106.             if (previous)
  107.                previous->cm_next = comentry;
  108.  
  109.             comcnt++;
  110.             previous = comentry;
  111.          }
  112.       }
  113.    } else {
  114.       segment = (struct Segment *) (((long) DEVINFO->di_NetHand)<<2);
  115.       while ((segment) && (comentry = AllocRemember (&ComRememberKey, sizeof (struct CommandEntry), MEMF_ANY|MEMF_CLEAR))) {
  116.          if (! *first)
  117.             *first = comentry;
  118.          if (previous)
  119.             previous->cm_next = comentry;
  120.    
  121.          comentry->cm_adr = (char *) segment;
  122.          sprintf (comentry->cm_address, "$%08x", segment);
  123.          strncpy (comentry->cm_name, (char *) &segment->seg_Name + 1, (UBYTE) segment->seg_Name[0]);
  124.    
  125.          if (tmp = GetUCType (segment->seg_UC)) {
  126.             strcpy (comentry->cm_uc, tmp);
  127.    
  128.             strcpy (comentry->cm_lower, ESC "c---");
  129.             strcpy (comentry->cm_upper, ESC "c---");
  130.             strcpy (comentry->cm_size, ESC "c---");
  131.    
  132.             comcnt++;
  133.             previous = comentry;
  134.          } else {
  135.             sprintf (comentry->cm_uc, "%d", segment->seg_UC - 1);
  136.    
  137.             seg = (long *) (((long) segment->seg_Seg)<<2);
  138.             comcnt++;
  139.             while (seg) {
  140.                sprintf (comentry->cm_lower, "$%x", ((char *) seg) + 4);
  141.                size = *(seg - 1);
  142.                sprintf (comentry->cm_size, "%d", size);
  143.                sprintf (comentry->cm_upper, "$%x", ((char *) seg) - 4 + size);
  144.    
  145.                previous = comentry;
  146.                if (seg = (long *) ((*seg)<<2)) {
  147.                   comentry = AllocRemember (&ComRememberKey, sizeof (struct CommandEntry), MEMF_ANY|MEMF_CLEAR);
  148.                   if (previous)
  149.                      previous->cm_next = comentry;
  150.                   comentry->cm_address[0] = ' ';
  151.                }
  152.             }
  153.          }
  154.          segment = (struct Segment *) (segment->seg_Next<<2);
  155.       }
  156.    }
  157.    return (comcnt);
  158. }
  159.  
  160. void PrintCommands (char *filename) {
  161.    int i=1;
  162.    BPTR handle;
  163.    struct CommandEntry *entryp;
  164.  
  165.    handle = HandlePrintStart (filename);
  166.    if ((handle) && (PrintOneLine (handle, "\n  Address  Name            UseCount     Lower     Upper    Size\n\n"))) {
  167.       if (! WI_Commands) {
  168.          i = GetCommands (&entryp);
  169.       }
  170.       if (i) {
  171.          for (i=0;;i++) {
  172.             if (WI_Commands)
  173.                DoMethod (comlist,MUIM_List_GetEntry,i,&entryp);
  174.             if (!entryp) break;
  175.  
  176.             sprintf (tmpstr2, " %9ls %-15.15ls %8ls", entryp->cm_address, entryp->cm_name, entryp->cm_uc);
  177.             if ((entryp->cm_uc[0] == 'I') || (entryp->cm_uc[0] == 'S') || (entryp->cm_uc[0] == 'D')) {
  178.                sprintf (tmpstr, " %9ls %9ls %7ls\n", entryp->cm_lower+2, entryp->cm_upper+2, entryp->cm_size+2);
  179.                strcat (tmpstr2, tmpstr);
  180.             } else {
  181.                sprintf (tmpstr, " %9ls %9ls %7ls\n", entryp->cm_lower, entryp->cm_upper, entryp->cm_size);
  182.                strcat (tmpstr2, tmpstr);
  183.             }
  184.             if (! (PrintOneLine (handle, tmpstr2)))
  185.                break;
  186.  
  187.             if (! WI_Commands)
  188.                entryp = entryp->cm_next;
  189.          }
  190.       }
  191.    }
  192.    HandlePrintStop();
  193. }
  194.  
  195. void ShowCommands (void) {
  196.    struct   CommandEntry   *com;
  197.  
  198.    ApplicationSleep();
  199.    set (comlist,MUIA_List_Quiet,TRUE);
  200.    set (comlist,MUIA_List_CompareHook,comlist_cmphook_ptr);
  201.    set (BT_ComRemove, MUIA_Disabled, TRUE);
  202.  
  203.    FreeCommands();
  204.    comcnt = GetCommands (&com);
  205.  
  206.    while (com) {
  207.       InsertSortedEntry (comlist, (APTR *) &com);
  208.       com = com->cm_next;
  209.    }
  210.  
  211.    SetCountText (comcount, comcnt);
  212.    AwakeApplication();
  213.    set (comlist,MUIA_List_Quiet,FALSE);
  214. }
  215.  
  216. void SendComList (void) {
  217.    struct   CommandEntry   *com;
  218.  
  219.    FreeCommands();
  220.    comcnt = GetCommands (&com);
  221.  
  222.    while (com) {
  223.       SendEncodedEntry ((UBYTE *) com, sizeof (struct CommandEntry));
  224.       com = com->cm_next;
  225.    }
  226.    FreeCommands();
  227. }
  228.  
  229.